package modulos;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import auxiliary.Database;

public class TableModelPlan extends AbstractTableModel {

	// Vector cache;
	Vector headers;
	int colCount;

	Database db;
	Object[][] data;
	Date utildate;

	TableModelPlan() {

		// cache = new Vector();

		SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
		String firsttime = "07:00";
		String endtime = "18:00";

		Calendar cal = Calendar.getInstance();
		Calendar endcal = Calendar.getInstance();
		try {
			cal.setTime(formatter.parse(firsttime));
			endcal.setTime(formatter.parse(endtime));
		} catch (ParseException e1) {
			e1.printStackTrace();
		}

		headers = new Vector();

		headers.addElement(formatter.format(cal.getTime()));

		while (cal.before(endcal)) {
			cal.add(Calendar.MINUTE, 6);
			headers.addElement(formatter.format(cal.getTime()));
			//System.out.println(formatter.format(cal.getTime()));
		}
	}

	public void updateTable() {

		data = new Object[4][headers.size()];

		colCount = headers.size();

		for (int i = 0; i < 4; i++) {
			data[i][0] = "Dispensacion";
			data[i][1] = "Limpieza Tanque";
			data[i][2] = "Produccion";
			data[i][3] = "Llenado";
			data[i][4] = "Loteado";
			data[i][5] = "Etiqueteado";
			data[i][6] = "Bandas";
			data[i][7] = "Empaque";
			data[i][8] = "Limpieza de Tanque";
			data[i][9] = "nueve";
			data[i][10] = "diez";
		}

		fireTableChanged(null);

	}

	@Override
	public int getColumnCount() {
		return colCount;
	}

	@Override
	public int getRowCount() {
		return data.length;
	}

	@Override
	public Object getValueAt(int row, int col) {
		// System.out.println(data[row][col]);
		return data[row][col];
	}

	public String getColumnName(int i) {
		return headers.get(i).toString();
	}

}